# -*- coding: utf-8 -*-

import json

class ConfigUtil():

    def __init__(self):
        self.config_path = 'config/config.json'
        self.default_config = {'host': '127.0.0.1', 'db': 'test', 'user': 'root', 'pwd': '123'}

    def get_json(self):
        try:
            with open(self.config_path,'r') as load_f:
                load_dict = json.load(load_f)
                return load_dict
        except Exception:
            self.update_json(self.default_config)
            return self.default_config

    def update_json(self, data):
        with open(self.config_path, "w") as f:
            json.dump(data, f)
            print("配置文件已更新...")